package practice.aop.spring.annot;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;

//  @Aspect  어노테이션  적용
@Aspect
// advice 실행 순서 정의
@Order(3)
public class ProfilingAspect {
	// @Pointcut 어노테이션을 이용해서 Pointcut 정의
	@Pointcut("execution(public  * min.chapter.five.board..*(..))")
	private void profileTarget() {
	}

	// @Around 어노테이션을 이용해서 Around Advice 구현
	@Around("profileTarget()")
	public Object trace(ProceedingJoinPoint joinPoint) throws Throwable {
		String signatureString = joinPoint.getSignature().toShortString();
		System.out.println(signatureString + " 시작");
		long start = System.currentTimeMillis();
		try {
			Object result = joinPoint.proceed();
			return result;
		} finally {
			long finish = System.currentTimeMillis();
			System.out.println(signatureString + " 종료");
			System.out.println(signatureString + " 실행 시간  :  "
					+ (finish - start) + "ms");
		}
	}
}
